<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Allocator List</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/layer/layer.js"></script>
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/layer/skin/default/layer.css" />
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  function addNewAssignMeter() {
		loadNewModal(path+"beshs/assignMeterAction!queryMeterForManage.do?date="+new Date(),"Add the heat allocation table","500px","1050px");
	}  
	
	function showMeterDetail(assignMeterUID) {
		loadNewModal(path+"beshs/assignMeterAction!queryMeterDetail.do?assignMeterUID="+assignMeterUID+"&date="+new Date(),"Check the heat distribution table","460px","680px");
	}
	
	function updateAssignMeter(assignMeterUID) {
		loadNewModal(path+"beshs/assignMeterAction!queryMeterForManage.do?assignMeterUID="+assignMeterUID+"&date="+new Date(),"Modify the heat distribution table","500px","1050px");
	}
  	
  	function deleteAssignMeter(assignMeterUID) {
  		Dialog.confirm("Are you sure to delete this allocator?", function() {
  			$.getJSON(path+"beshs/assignMeterActionJson!deleteAssignMeterByUID.do?date="+new Date(), {
  				assignMeterUID: assignMeterUID
  	  		}, function(data) {
  	  			if(data.success) {
  	  				Dialog.alert("Successful Operation！", function() {
  	  					window.location = path + "beshs/assignMeterAction!queryAssignMeterPage.do?date="+new Date();
  	  				});
  	  			} else {
  	  				Dialog.alert("System error, please contact adminitrator！");
  	  			}
  	  		});
  		});
  	}
  	
  	$(function(){
  		$("input[name='query']").click(function(){
  			var seriousNum = $("input[name='seriousNum']").val();
  			var projectUID = $("select[name='projectUID']").val();
  			var communityUID = $("select[name='communityUID']").val();
  			var buildingUID = $("select[name='buildingUID']").val();
  			var heatRoomUID = $("select[name='heatRoomUID']").val();
  			window.location = path + "beshs/assignMeterAction!queryAssignMeterPage.do?seriousNum="+encodeURIComponent(seriousNum)
  					+"&projectUID="+projectUID
  					+"&communityUID="+communityUID
  					+"&buildingUID="+buildingUID
  					+"&heatRoomUID="+heatRoomUID
  					+"&date="+new Date();
  		});
  		$("input[name='add']").click(function(){
  			addNewAssignMeter();
  		});
  	});
  </script>
  <body>
  	<div class="content_all">
	  	<!--查询条件-->
	  	<div class="search">
	    	<form action=""><table cellpadding="0" cellspacing="0">
	    		<tr>
	    			<th>Project：</th>
			        <td>
			        	<s:select name="projectUID" list="projectList" listKey="id" listValue="projectName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
			        </td>
			        <th>District：</th>
	      			<td>
		      			<script type="text/javascript">
		      				function reloadCommunitys(projectUID, communityUID) {
		      					$("select[name='communityUID']").children("option").slice(1).remove();
		      					if(projectUID!=null && projectUID!="") {
		      						$.getJSON(path+"beshs/communityActionJson!queryCommunitysByBelongs.do?date="+new Date(), {
		      							projectUID: projectUID
		      						}, function(data){
		      							for(var index=0; index<data.length; index++) {
		      								if(communityUID!=null && communityUID!="" && communityUID==data[index].id) {
			        							$("select[name='communityUID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].communityName+"</option>");
			        						} else {
			        							$("select[name='communityUID']").append("<option value='"+data[index].id+"'>"+data[index].communityName+"</option>");
			        						}
		      							}
		      						});
		      					}
		      				}
		      					
		      				$(function() {
		      					$("select[name='projectUID']").change(function(){
				        			var projectUID = $(this).val();
				        			var communityUID = $("select[name='communityUID']");
				        			reloadCommunitys(projectUID, communityUID);
				        		});
		      				});
		      			</script>
		      			<s:select name="communityUID" list="communityList" listKey="id" listValue="communityName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
	      			</td>						
			       	<th>Building：</th>
			       	<td>
			       		<script type="text/javascript">
				       		function reloadBuildings(projectUID, communityUID, buildingUID) {
			        			$("select[name='buildingUID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/buildingActionJson!queryBuildingsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(buildingUID!=null && buildingUID!="" && buildingUID==data[index].id) {
	        								$("select[name='buildingUID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].buildingName+"</option>");
	        							} else {
	        								$("select[name='buildingUID']").append("<option value='"+data[index].id+"'>"+data[index].buildingName+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		
			        		$(function(){
			        			$("select[name='projectUID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='communityUID']").val();
			        				var buildingUID = $("select[name='buildingUID']").val();
			        				reloadBuildings(projectUID, communityUID, buildingUID);
			        			});
			        			
			        			$("select[name='communityUID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='projectUID']").val();
			        				var buildingUID = $("select[name='buildingUID']").val();
			        				reloadBuildings(projectUID, communityUID, buildingUID);
			        			});
			        		});
			       		</script>
			       		<s:select name="buildingUID" list="buildingList" listKey="id" listValue="buildingName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
			       	</td>
	      			<th>Heat User：</th>
			        <td>
			        	<script type="text/javascript">
			        		function reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID) {
			        			$("select[name='heatRoomUID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/heatRoomActionJson!queryHeatRoomsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID,
			        				buildingUID: buildingUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(heatRoomUID!=null && heatRoomUID!="" && heatRoomUID==data[index].id) {
	        								$("select[name='heatRoomUID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].houseNo+"</option>");
	        							} else {
	        								$("select[name='heatRoomUID']").append("<option value='"+data[index].id+"'>"+data[index].houseNo+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		$(function(){
			        			$("select[name='projectUID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='communityUID']").val();
			        				var buildingUID = $("select[name='buildingUID']").val();
			        				var heatRoomUID = $("select[name='heatRoomUID']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        			
			        			$("select[name='communityUID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='projectUID']").val();
			        				var buildingUID = $("select[name='buildingUID']").val();
			        				var heatRoomUID = $("select[name='heatRoomUID']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        			
			        			$("select[name='buildingUID']").change(function(){
			        				var buildingUID = $(this).val();
			        				var projectUID = $("select[name='projectUID']").val();
			        				var communityUID = $("select[name='communityUID']").val();
			        				var heatRoomUID = $("select[name='heatRoomUID']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        		});
			        	</script>
						<s:select name="heatRoomUID" list="heatRoomList" listKey="id" listValue="houseNo" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
					</td>
				</tr>
				<tr>
			        <th>Allocator No.：</th>
			        <td><input name="seriousNum" value="<s:property value='seriousNum' />" type="text" class="s_input" /></td>
			        <td colspan="6"><input name="query" type="button" value="Query" class="s_btn" />
			        	<input name="reset" type="reset" value="Reset" class="s_btn" />
			        	<s:if test="superManager.contains(#session.user.userID) 
								|| loginUserRoleIDList.contains(sysadmin) 
								|| loginUserRoleIDList.contains(sysShareManager)">
							<input name="add" type="button" value="Add" class="s_btn" />
						</s:if>
	        		</td>
	      		</tr>
	    	</table></form>
	  	</div>
	  	<!--查询列表-->
	  	<div class="search_table_all">
	    	<table class="search_table" cellspacing="0" cellpadding="0">
	      		<thead>
	        		<tr>
		          		<th style="width:30px;">Serial No.</th>
			          	<th>Allocator No.</th>
			          	<th>Allocator Model</th>
						<th>Concentrator No.</th>
						<th>Radiator No.</th>
						<th>Installation Time</th>
			          	<th>Operation</th>
	        		</tr>
	      		</thead>
	      		<tbody>
	      			<s:iterator value="assignMeterPage.list" var="assignMeter" status="status">
	      				<tr>
		          			<td><s:property value="#status.index+1" /></td>
		          			<td><s:property value="#assignMeter.seriousNum" /></td>
		          			<td><s:property value="#assignMeter.model" /></td>
		          			<td><s:property value="pageConcentratorMap.get(#assignMeter.concentratorID)" /></td>
		          			<td><s:property value="pageSinkerMap.get(#assignMeter.heatSinkID)" /></td>
		          			<td><s:date name='#assignMeter.installDate' format='yyyy-MM-dd' nice='false' /></td>
		          			<td><a href="javascript:showMeterDetail('<s:property value='#assignMeter.id' />')">[Check]</a>
		          				<s:if test="superManager.contains(#session.user.userID) 
										|| loginUserRoleIDList.contains(sysadmin) 
										|| loginUserRoleIDList.contains(sysShareManager)">
									&nbsp;&nbsp;<a href="javascript:updateAssignMeter('<s:property value='#assignMeter.id' />')">[Modify]</a>
		          					&nbsp;&nbsp;<a href="javascript:deleteAssignMeter('<s:property value='#assignMeter.id' />')">[Delete]</a>
								</s:if>
		          			</td>
		        		</tr>
	      			</s:iterator>
	      		</tbody>
	    	</table>
	  	</div>
	  	<!--操作按钮&分页-->
	  	<script type="text/javascript">
	  		function pageUp(pageIndex) {
	  			var seriousNum = $("input[name='seriousNum']").val();
	  			var projectUID = $("select[name='projectUID']").val();
	  			var communityUID = $("select[name='communityUID']").val();
	  			var buildingUID = $("select[name='buildingUID']").val();
	  			var heatRoomUID = $("select[name='heatRoomUID']").val();
	  			window.location = path + "beshs/assignMeterAction!queryAssignMeterPage.do?pageIndex="+(pageIndex-1)
	  					+"&seriousNum="+encodeURIComponent(seriousNum)
	  					+"&projectUID="+projectUID
	  					+"&communityUID="+communityUID
	  					+"&buildingUID="+buildingUID
	  					+"&heatRoomUID="+heatRoomUID
	  					+"&date="+new Date();
	  		}
	  		
			function pageDown(pageIndex) {
				var seriousNum = $("input[name='seriousNum']").val();
	  			var projectUID = $("select[name='projectUID']").val();
	  			var communityUID = $("select[name='communityUID']").val();
	  			var buildingUID = $("select[name='buildingUID']").val();
	  			var heatRoomUID = $("select[name='heatRoomUID']").val();
				window.location = path + "beshs/assignMeterAction!queryAssignMeterPage.do?pageIndex="+(pageIndex+1)
						+"&seriousNum="+encodeURIComponent(seriousNum)
						+"&projectUID="+projectUID
						+"&communityUID="+communityUID
						+"&buildingUID="+buildingUID
						+"&heatRoomUID="+heatRoomUID
						+"&date="+new Date();
	  		}
			
			function pageLocate(pageIndex) {
				var seriousNum = $("input[name='seriousNum']").val();
	  			var projectUID = $("select[name='projectUID']").val();
	  			var communityUID = $("select[name='communityUID']").val();
	  			var buildingUID = $("select[name='buildingUID']").val();
	  			var heatRoomUID = $("select[name='heatRoomUID']").val();
				window.location = path + "beshs/assignMeterAction!queryAssignMeterPage.do?pageIndex="+pageIndex
						+"&seriousNum="+encodeURIComponent(seriousNum)
						+"&projectUID="+projectUID
						+"&communityUID="+communityUID
						+"&buildingUID="+buildingUID
						+"&heatRoomUID="+heatRoomUID
						+"&date="+new Date();
			}
	  	</script>
	  	<div class="search_control">
	    	<div class="right">
	      		<div class="pages">
	      		<!-- 上一页 -->
	      			<s:if test="pageIndex==1">
	      				<a href="javascript:void(0)" class="disabled">Former Page</a>
	      			</s:if>
	      			<s:else>
	      				<a href="javascript:pageUp(<s:property value='pageIndex' />)">Former Page</a>
	      			</s:else>
	      		<!-- 页码 -->
	      			<s:if test="pageSize<=0">
	      			<!-- 若分页页数未初始化或为0，则只显示第一页 -->
	      				<a href="javascript:void(0)" class="current">1</a>
	      			</s:if>
	      			<s:elseif test="pageSize<=9">
	      			<!-- 页数在9页以内全显示 -->
	      				<s:bean name="org.apache.struts2.util.Counter" id="counter">
	      					<s:param name="first" value="1" />
	      					<s:param name="last" value="pageSize" />
	      					<s:iterator value="counter" var="index">
	      						<s:if test="#index==pageIndex">
		      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
		      					</s:if>
		      					<s:else>
		      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
		      					</s:else>
	      					</s:iterator>
	      				</s:bean>
	      			</s:elseif>
	      			<s:else>
	      			<!-- 页数在9页以上则部分显示 -->
	      				<s:if test="pageIndex<7">
	      				<!-- 页码小于7时，先显示前7页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="7" />
	      						<s:iterator value="frontCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      				<!-- 显示最后两页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="lastCounter">
	      						<s:param name="first" value="pageSize-1" />
	      						<s:param name="last" value="pageSize" />
	      						<s:iterator value="lastCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      				</s:if>
	      				<s:elseif test="pageIndex>=7 && (pageSize-pageIndex)>2">
	      				<!-- 页码不小于7，但又不接近总页数时，分三部分显示：1-3、中间三页、最后一页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="3" />
	      						<s:iterator value="frontCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<s:bean name="org.apache.struts2.util.Counter" id="middleCounter">
	      						<s:param name="first" value="pageIndex-1" />
	      						<s:param name="last" value="pageIndex+1" />
	      						<s:iterator value="middleCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<a href="javascript:pageLocate(<s:property value='pageSize' />)"><s:property value="pageSize" /></a>
	      				</s:elseif>
	      				<s:else>
	      				<!-- 页码接近总页数，而且页码与总页数的差小于等于2时，分两部分显示：1-3、最后6页 -->
	      					<s:bean name="org.apache.struts2.util.Counter" id="frontCounter">
	      						<s:param name="first" value="1" />
	      						<s:param name="last" value="3" />
	      						<s:iterator value="frontCounter" var="index">
	      							<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
	      						</s:iterator>
	      					</s:bean>
	      					...
	      					<s:bean name="org.apache.struts2.util.Counter" id="lastCounter">
	      						<s:param name="first" value="pageSize-5" />
	      						<s:param name="last" value="pageSize" />
	      						<s:iterator value="lastCounter" var="index">
	      							<s:if test="#index==pageIndex">
			      						<a href="javascript:void(0)" class="current"><s:property value="#index" /></a>
			      					</s:if>
			      					<s:else>
			      						<a href="javascript:pageLocate(<s:property value='#index' />)"><s:property value="#index" /></a>
			      					</s:else>
	      						</s:iterator>
	      					</s:bean>
	      				</s:else>
	      			</s:else>
	      		<!-- 下一页 -->	
	      			<s:if test="pageSize>pageIndex">
	      				<a href="javascript:pageDown(<s:property value='pageIndex' />)">Next Page</a>
	      			</s:if>
	      			<s:else>
	      				<a href="javascript:void(0)" class="disabled">Next Page</a>
	      			</s:else>
	      		</div>
	    	</div>
	    	<div class="clear"></div>
	  	</div>
	  	<!-- 分页结束 -->
	</div>
  </body>
</html>
